package org.jeecg.modules.rental.controller.api;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.iot.cache.EBikeCache;
import org.jeecg.modules.rental.entity.RentalEBike;
import org.jeecg.modules.rental.service.IRentalEBikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 租赁Api接口信息
 * @Author: sean
 * @Date: 2024-04-26
 * @Version: V1.0
 */
@Api(tags = "租赁Api接口信息")
@RestController
@RequestMapping("/rental/api")
@Slf4j
public class ApiRentalController{
    @Autowired
    private IRentalEBikeService rentalCarService;

    @ApiOperation("根据条件查询车辆列表")
    @PostMapping("/ebike-list")
    public Result<List<RentalEBike>> ebikeList(@RequestBody RentalEBike rentalCar) {
        Result<List<RentalEBike>> rentalCars =  rentalCarService.listNoTenant(rentalCar); // 使用service层的方法
        return rentalCars;
    }

    @ApiOperation("根据id查询车辆")
    @GetMapping(value = "/ebike-get")
    public Result<RentalEBike> queryById(@RequestParam(name = "id", required = true) String id) {
        RentalEBike rentalCar = rentalCarService.getByIdNoTenant(id);
        if (rentalCar == null) {
            return Result.error("car.control.not.found", null);
        }
        return Result.OK(rentalCar);
    }

    @ApiOperation("创建租车车辆")
    @PostMapping("/create") //  新增 createRentalEBike 接口, 注意路径是 /rental/rentalCar/create
    public Result<Boolean> createEBike(@RequestBody RentalEBike rentalCar) {
        //TODO 需要确认添加到哪个租户
        boolean ok = rentalCarService.save(rentalCar); //  使用 save 方法保存新车辆
        return Result.OK(ok);
    }

    @ApiOperation("根据ID更新车辆信息")
    @PostMapping("/updateEBikeById")
    public Result<Boolean> updateById(@RequestBody RentalEBike rentalCar) {
        //TODO 可能应为租户隔离需要修改代码
        boolean ok = rentalCarService.updateById(rentalCar);
        return Result.OK(ok);
    }


}
